//
//  RecommendViewController.m
//  BurnFat
//
//  Created by lanou3g on 16/5/6.
//  Copyright © 2016年 ZhaoYingWei. All rights reserved.
/**
 * "userInfo":{
 "uid":"5404319553909475551",
 "userName":"小斌哥119",//明子
 "sex":"1", //性别
 "typeId":"0",
 "typeName":"",
 "summary":"依旧你们的小斌哥，你给我一份支持，我还你一片天空。",
 "status":"0",
 "tags":"",
 "portrait":"http://himg.bdimg.com/sys/portrait/item/864be5bfabe6898be7baa2e4babae8b5b5e5b08fe4b9907c3f",   //小头像  //recomDesc下面标签介绍 objUrl 下面视频图 
 "myFollow":1 //是否关注
 },
 */
#import "RecommendViewController.h"
#import "RecomedModel.h"
#import "RecommedCell.h"
#import "YWLayout.h"
#import "PersonneController.h"
#import "UIButton+IndexPath.h"
#import "HeaderFile.h"
@interface RecommendViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,RecommedCellDelegate>
@property(nonatomic,strong)NSMutableArray *recomedArray;
@property(nonatomic,strong)NSMutableArray *sizeArray;
@property(nonatomic,strong)UICollectionView *collectionView;
@end
static NSString *const ItemID = @"recommed";
@implementation RecommendViewController
-(NSMutableArray *)sizeArray
{
    if (_sizeArray == nil) {
        _sizeArray =[[NSMutableArray alloc]init];
    }
    return _sizeArray;
}
-(NSMutableArray *)recomedArray
{
    if (_recomedArray == nil) {
        _recomedArray = [NSMutableArray array];
    }
    return _recomedArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"用户推荐";
  ;
     [self requestRecommendMainPageData];
     [self setupCollectionView];
   
   
    
}
-(void)setupCollectionView
{
    
  
    self.collectionView = [[UICollectionView alloc]initWithFrame:[UIScreen mainScreen].bounds collectionViewLayout:[[YWLayout alloc]init]];
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
     [self.view addSubview:self.collectionView];
   
    self.collectionView.backgroundColor =[UIColor whiteColor];
    [self.collectionView registerNib:[UINib nibWithNibName:@"RecommedCell" bundle:nil] forCellWithReuseIdentifier:@"recommed"];
    
}
-(void)requestRecommendMainPageData
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"devId"]=@"3d18bde7ef497253d9c6749ce1e20c3ebbdb6c7f";
    params[@"devType"] = @"1";
    params[@"logid"] = @"c7da344814c0b2c637237a5b088f405b";
    params[@"uid"] = @"5116089179234813407";
     [HttpTool Post:@"http://119.75.222.113/app/discover" params:params success:^(id response) {
       
        NSDictionary *data = response[@"data"];
        NSArray *vipListArray = data[@"vipList"];
      
        for (NSDictionary * modeldict in vipListArray) {
            
            RecomedModel *model = [[RecomedModel alloc]init];
            [model setValuesForKeysWithDictionary:modeldict];
            [self.recomedArray addObject:model];
        }
         dispatch_async(dispatch_get_main_queue(), ^{
             [self.collectionView reloadData];
         });
        
    } failure:^(NSError *error) {
        
        
    }];
    
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
   
    return self.recomedArray.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    RecommedCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"recommed" forIndexPath:indexPath];
    RecomedModel *m = self.recomedArray[indexPath.item];
    cell.models = m;
    cell.FllowedBtn.indexPath = indexPath;
    cell.delegate = self;
    
      return cell;
}
-(void)cellBeClicedWith:(RecommedCell *)sender
{
    
    NSLog(@"%zd",sender.FllowedBtn.indexPath.row);
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    [collectionView deselectItemAtIndexPath:indexPath animated:YES];
    PersonneController *pVC = [[PersonneController alloc]init];
    [self.navigationController pushViewController:pVC animated:YES];
    
}

@end
